/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef WISHMASTER_TEMPLATETHREADBUIDLER_H
#define WISHMASTER_TEMPLATETHREADBUIDLER_H

#include <QString>
#include "threadbuilder.h"

namespace Wishmaster
{
	class TemplateThreadBuilder : public ThreadBuilder
	{
	public:
		TemplateThreadBuilder();
		virtual ~TemplateThreadBuilder();

		virtual bool loadTemplate(const QString& filename);

		virtual void start(const QString& title);
		virtual void emitPost(PostPtr post);
		virtual void end();

		virtual bool save(const QString& path);
		virtual bool singleFile();
		virtual QString id();
		virtual QString text();
		virtual QString filter();

		virtual QWidget* createConfigWidget();
		virtual bool applyConfig(QWidget* cfgWidget);

		virtual ThreadBuilderPtr clone();

	private:
		QByteArray load(const QString& filename);
		QByteArray addAttachments(PostPtr post);
		QString makeFilePath(PostPtr post, int index);
		QString makeThumbPath(PostPtr post, int index);
		QMap<QString, QString> loadMap(const QString& filename);
		QMap<QString, QImage> m_images;
		QByteArray m_result;
		QByteArray m_head;
		QByteArray m_post;
		QByteArray m_tail;
		QByteArray m_image;
		QStringList m_includes;
		unsigned long m_id;
		QString m_templateFilename;
	};
}

#endif
